package com.xyx.www;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

public class Test0802 {
	public static void main(String[] args) {
		test01();
	}

	private static void test01() {
		Map<String,Object> map0 = new HashMap<String,Object>();
		// Map map0 = new LinkedHashMap();有序
		// Map map0 = new TreeMap();排序
		map0.put("guojunchi", 17);
		map0.put("ganchuanhua", 18);
		map0.put("wangfei", 19);
		map0.put("hezhanqiang", 20);
		map0.put("zhengming", 21);
		System.out.println("增强型for循环Map中Key的集合");
		// 先取出 Key的Set集合，然后再对其进行遍历
		Set<String> keyset = map0.keySet();
		for (String obj : keyset) {
			System.out.println("键-" + obj + "值-" + map0.get(obj));
		}
		System.out.println("迭代遍历");
		Iterator<String> it = keyset.iterator();
		while (it.hasNext()) {
			String str= it.next();
			System.out.println("键-" + str + "值" + map0.get(str));
		}
		System.out.println("-------------");
		System.out.println("通过Entry遍历");
		System.out.println("Entry获取map0中所有的键值对");
		// 先取出 Entry的Set集合，然后再对其进行遍历
		Set<Entry<String,Object>> entry = map0.entrySet();
		for (Entry<String,Object> en : entry) {
			// 向下塑形
			//Entry en = (Entry) object;泛型之后不再需要向下塑形
			System.out.println("键-" + en.getKey() + "值-" + en.getValue());
		}
		Iterator<Entry<String,Object>>it1=entry.iterator();
		
		while(it1.hasNext()) {
			Entry<String,Object> obj=it1.next();
			System.out.println("键-" + obj.getKey() + "值-" + obj.getValue());

		}
	}
}
